<template>
  <div class="flex flex-col h-full">
    <SearchContainer is-width @search="getData" @reset="onReset">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '78px' } }">
        <a-form-item name="keyword" class="!w-72">
          <a-input v-model:value="formState.keyword" placeholder="姓名/助记码/手机号/卡号/身份证号" allow-clear />
        </a-form-item>
        <a-form-item name="dateRange" label="" class="w-[500px] ml-3">
          <a-radio-group v-model:value="formState.queryType" @change="getData()">
            <a-radio :value="1">姓名一致</a-radio>
            <a-radio :value="2">手机号一致</a-radio>
            <a-radio :value="3">姓名与手机号一致</a-radio>
            <a-radio :value="4">身份证号一致</a-radio>
          </a-radio-group>
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <a-button type="primary" :disabled="defaultCheckedKeys.length !== 2" class="mb-2 mr-2" @click="toMergePage">合并</a-button>
      <BaseTable
        :loading="loading"
        column-code="000597"
        fill
        row-key="brId"
        :row-selection="{ selectedRowKeys: defaultCheckedKeys, onChange: onSelectChange }"
        :scroll="{ x: 2650 }"
        :data-source="tableData"
        bordered
        :pagination="pagination"
        :exclude-columns="getSystemConfig('ENABLE_CHARGE_STANDARD_MODE') === '1' ? [] : ['chargeStdName']"
      >
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex == 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex == 'brYwyName'">
            {{ record.brYwyName || record.brYwy }}
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>
<script setup>
import { message } from 'ant-design-vue'
import { getSystemConfig } from '@/utils/systemConfig'

const router = useRouter()
const formRef = ref(null)
const isMedical = ref()
const formState = ref({
  keyword: '',
  queryType: 1
})
const defaultCheckedKeys = ref([])

const { loading, tableData, pagination, getData } = useTable({
  url: '/outp/brDataChange/getPatientList',
  params: formState.value,
  immediate: true,
  formatParams: (params) => {
    return {
      ...params
    }
  }
})

const toMergePage = async () => {
  if (defaultCheckedKeys.value.length === 2) {
    router.push({
      path: '/out-registration/patient-file/patient-merge/merge',
      query: {
        ids: defaultCheckedKeys.value
      }
    })
  } else {
    message.warning('请选择两项进行合并')
  }
}

const onReset = () => {
  formRef.value.resetFields()
  formState.value.keyword = ''
  formState.value.queryType = 1
}
const onSelectChange = (selectedRowKeys) => {
  defaultCheckedKeys.value = selectedRowKeys
}

onMounted(async () => {
  isMedical.value = getSystemConfig('IS_EXIST_MEDICAL_INSURANCE') === '1' //是否启用医保
})
</script>
